//
//  EventCellFrame.m
//  Runone
//
//  Created by runone02 on 16/10/11.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "EventCellFrame.h"

@implementation EventCellFrame

- (void) setLModel:(EventDealListModel *)lModel {
    _lModel = lModel;
    
    //圆点
    CGFloat circleX = 8;
    CGFloat circleY = 10;
    CGFloat circleH = 10;
    CGFloat circleW = 10;
    _circleIVFrame = CGRectMake(circleX, circleY, circleW, circleH);
    
    //时间label
    CGFloat timeX = 26;
    CGFloat timeY =  5;
    CGFloat timeH = 20;
    CGFloat timeW = 150;
    _timeFrame = CGRectMake(timeX, timeY, timeW, timeH);
    
    //上报人的label
    CGFloat recordX = CGRectGetMaxX(_timeFrame);
    CGFloat recordY = 5;
    CGFloat recordH = 20;
    CGFloat recordW = [UIScreen mainScreen].bounds.size.width - CGRectGetMaxX(_timeFrame);
    _recordFrame    = CGRectMake(recordX, recordY, recordW, recordH);
    
    CGFloat lineX = 10;
    CGFloat lineW = 6;
    CGFloat lineY = CGRectGetMaxY(_circleIVFrame) + 8;
    int count = (int)_lModel.PicturePath.count;
    //处理信息
    if ((![_lModel.DealDetail isEqualToString:@""]) && count > 0) { // 文字 图片都有
        CGSize  maxSize =  CGSizeMake([UIScreen mainScreen].bounds.size.width - 34 , MAXFLOAT);
        CGFloat dealX   = 26;
        CGFloat dealY   = CGRectGetMaxY(_timeFrame) + 8;
        CGFloat dealW   = [UIScreen mainScreen].bounds.size.width - 34;
        
        CGFloat dealH = [_lModel.DealDetail boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} context:nil].size.height;
        _dealFrame    = (CGRect){{dealX,dealY},{dealW,dealH}};
        
        CGFloat photosX = 26;
        CGFloat photosY = CGRectGetMaxY(_dealFrame) ;
        CGSize photosSize = [self photosSizeWithCount:count];
        
        _photoesFrame = (CGRect){{photosX,photosY},photosSize};
        _cellH        = CGRectGetMaxY(_photoesFrame) ;
        _lineVFrame   = CGRectMake(lineX, lineY, lineW, _cellH - lineY - 8);
    } else if (_lModel.DealDetail && count == 0) { //只有文字
        CGSize  maxSize =  CGSizeMake([UIScreen mainScreen].bounds.size.width - 34 , MAXFLOAT);
        CGFloat dealX   = 26;
        CGFloat dealY   = CGRectGetMaxY(_timeFrame) + 8;
        CGFloat dealW   = [UIScreen mainScreen].bounds.size.width - 34;
        
        CGFloat dealH = [_lModel.DealDetail boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} context:nil].size.height;
        _dealFrame    = (CGRect){{dealX,dealY},{dealW,dealH}};
        _cellH        = CGRectGetMaxY(_dealFrame) + 8;
        _lineVFrame   = CGRectMake(lineX, lineY, lineW, _cellH - lineY - 8);
    } else if ([_lModel.DealDetail isEqualToString:@""] && count > 0) { //只有图片
        CGFloat photosX   = 26;
        CGFloat photosY   = CGRectGetMaxY(_timeFrame) + 8;
        CGSize photosSize = [self photosSizeWithCount:count];
        
        _photoesFrame = (CGRect){{photosX,photosY},photosSize};
        _cellH        = CGRectGetMaxY(_photoesFrame);
        _lineVFrame   = CGRectMake(lineX, lineY, lineW, _cellH - lineY - 8);
    
    } else { //没文字 没图片
        _cellH = 30;
        _lineVFrame   = CGRectMake(lineX, lineY, lineW, _cellH - lineY - 8);
    }
    _bottomVFrame = CGRectMake(20, _cellH, [UIScreen mainScreen].bounds.size.width - 20, 1);
    
}

- (CGSize)photosSizeWithCount:(int)count {
    CGFloat photoW = [UIScreen mainScreen].bounds.size.width - 34;
    CGFloat photoH = (200 + 8) * count + 8;
    return CGSizeMake(photoW, photoH);
}




@end
